import {
    IsEnum,
    IsNumber,
    IsNotEmpty,
    IsString, IsOptional,
    MaxLength, IsArray,
    IsBoolean,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { MenuType } from '../entities/sys.entity';


export class CreateySysMenuDto {

    
    @IsString({
        message: '菜单名称不能未空',
    })
    @MaxLength(255, {
        message: '菜单名称超长',
    })
    @IsNotEmpty()
    @ApiProperty({description: '菜单名称'})
    label: string;

    @IsEnum(MenuType, {
        message: '菜单类型错误',
    })
    @ApiProperty({description: '菜单类型', enum: ['menu', 'menuitem']})
    type: MenuType;

    @IsOptional()
    @IsString({
        message: 'VUE组件名称类型错误',
    })
    @MaxLength(50, {
        message: 'VUE组件名称最大长度50',
    })
    @ApiProperty({description: 'VUE组件名称'})
    component_name?: string;

    @IsOptional()
    @IsString({
        message: 'VUE组件路径类型错误',
    })
    @MaxLength(255, {
        message: 'VUE组件路径最大长度255',
    })
    @ApiProperty({description: 'VUE组件路径'})
    component_path?: string;

    @IsOptional()
    @IsString({
        message: '菜单图标错误',
    })
    @MaxLength(255, {
        message: '菜单图标最大长度255',
    })
    @ApiPropertyOptional({description: '菜单图标'})
    component_icon?: string;

    @IsOptional()
    @IsNumber(
        {},
        {
            message: '菜单序号类型错误',
        },
    )
    @ApiPropertyOptional({description: '序号'})
    orderno?: number;

    @IsOptional()
    @IsNumber(
        {},
        {
            message: '父ID类型错误',
        },
    )
    @ApiProperty({description: '父ID'})
    parentId?: number;
}



export class MoveSysMenuDto {
    @IsNumber(
        {},
        {
            message: 'id参数类型错误',
        },
    )
    id: number;

    @IsOptional()
    @IsNumber(
        {},
        {
            message: 'parent_id参数类型错误',
        },
    )
    parent_id: number;
}

export class CreateSysActionDto {
    @IsString()
    @IsNotEmpty({
        message: '名称不能为空',
    })
    @MaxLength(255)
    @ApiProperty({description: '功能名称', required: true})
    label: string;

    @IsString()
    @IsNotEmpty({
        message: 'URL不能为空',
    })
    @MaxLength(255)
    @ApiProperty({
        description: '功能URL', required: true
    })
    url: string;

    @IsOptional()
    @MaxLength(100)
    @ApiPropertyOptional({description:'备注'})
    remark: string;
}

export class UpdatePwDto {
    @IsString()
    @IsNotEmpty({
        message: '用户名称不能为空',
    })
    @ApiProperty({
        description: '账号'
    })
    oper: string;

    @IsString()
    @IsNotEmpty({
        message: '旧密码不能为空',
    })
    @ApiProperty({
        description: '旧密码'
    })
    oldPw: string;

    @IsString()
    @IsNotEmpty({
        message: '新密码不能为空',
    })
    @ApiProperty({
        description: '新密码'
    })
    newPw: string;
}

export class GetActionsByMenuDto {
    @IsNumber()
    @IsNotEmpty({
        message: '菜单不能为空',
    })
    @ApiProperty({description: '菜单ID'})
    menuId: number;
}


export class CreateMenuActionDto {
    @IsNumber()
    @IsNotEmpty({
        message: '菜单参数不能为空',
    })
    @ApiProperty({ description: '菜单ID'})
    menuId: number;

    @IsNumber()
    @IsNotEmpty({
        message: 'action参数不能为空',
    })
    @ApiProperty({ description: '功能ID'})
    actionId: number;

    @IsBoolean()
    @IsOptional()
    necessary: boolean;
}

export class CreateMenuActionsDto {

    @IsArray({
        each: true,
        message: '菜单功能参数错误'
    })
    datas: CreateMenuActionDto[]
}